package com.eshop.we.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.eshop.we.business.UserBusiness;
import com.eshop.we.result.Result;
import com.eshop.we.user.dto.UserInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    UserBusiness userBusiness;

    @GetMapping("/getuserpage")
    public Result getUserPageList(@RequestParam(required = false)String name,@RequestParam(required = false)String mobile,@RequestParam(required = false)String schoolName,
                                  @RequestParam(required = false)String startDate,@RequestParam(required = false)String endDate,
                                  @RequestParam(required = false,defaultValue = "1")Integer pageNum,@RequestParam(required = false,defaultValue = "20")Integer pageSize)throws Exception{

        Page<UserInfoDto> page=new Page<>(pageNum,pageSize);
        page=userBusiness.selectUserPage(page,name,mobile,schoolName,startDate,endDate);
        return Result.success(page);

    }

    @GetMapping("/getuserinfo")
    public Result getUserInfo(@RequestParam(required = true)Integer userId){
      return Result.success(userBusiness.getUserInfo(userId));
    }
}
